package main

import (
	"fmt"
	"os"
)

func main() {
	readFile()
	eval(1, 2, "+")
	eval(1, 2, "-")
	eval(1, 2, "*")
	eval(1, 2, "/")
	fmt.Println(grade(50), grade(90))
}

func grade(score int) string {
	g := ""
	switch {
	case score < 60:
		g = "F"
		fallthrough
	case score < 80:
		g = "C"
	case score < 90:
		g = "B"
	default:
		g = "A"
	}
	return g
}

func eval(a, b int, op string) int {
	var result int
	//如果不需要break，使用 fallthrough
	switch op {
	case "+":
		result = a + b
	case "-":
		result = a - b
	case "*":
		result = a * b
	case "/":
		result = a / b
	default:
		panic("unsupported operator:" + op)
	}
	fmt.Printf("%d %s %d = %d \n", a, op, b, result)
	return result
}

func readFile() {
	const filename = "go.mod"
	//合并写法
	if file, err := os.ReadFile(filename); err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("read content: \n%s\n", file)
	}

	file, err := os.ReadFile(filename)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("read content: \n%s\n", file)
	}
}
